import { ActionContext } from 'vuex'
import { IRootState } from '../../rootState'
import { state, getters, AppState } from './entity'
import { LocalCache, LocalKey } from '@/utils/cache'

const mutations = {
    // 设置版本号
    SET_VERSION: (state: AppState, version: string) => {
        LocalCache.set(LocalKey.VERSION, version);
        state.version = version;
    },
    SET_APP_INFO: (state: AppState, appInfo: any) => {
        state.appInfo = appInfo;
    },
    SET_THEME: (state: AppState, theme: string) => {
        state.theme = theme;
    }
}

const actions = {
    SetVersion({ commit }: ActionContext<AppState, IRootState>, version: string) {
        commit('SET_VERSION', version);
    }
}

export default {
    namespace: 'app',
    state,
    mutations,
    actions,
    getters
};